package com.draven.mall.controller;

import com.draven.mall.common.ApiResponse;
import com.draven.mall.entity.RiderApplication;
import com.draven.mall.service.RiderAuditService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 骑手审核控制器
 */
@RestController
@RequestMapping("/api/admin/rider")
public class RiderAuditController {

    @Autowired
    private RiderAuditService riderAuditService;

    /**
     * 获取待审核骑手列表
     */
    @GetMapping("/pending")
    public ApiResponse getPendingRiders() {
        List<RiderApplication> riders = riderAuditService.getPendingRiders();
        return ApiResponse.success(riders);
    }

    /**
     * 获取骑手详情
     */
    @GetMapping("/{id}")
    public ApiResponse getRiderDetail(@PathVariable Long id) {
        RiderApplication rider = riderAuditService.getRiderById(id);
        if (rider != null) {
            return ApiResponse.success(rider);
        } else {
            return ApiResponse.error("骑手信息不存在");
        }
    }

    /**
     * 审核骑手
     */
    @PostMapping("/audit")
    public ApiResponse auditRider(@RequestBody Map<String, Object> params) {
        Long id = Long.parseLong(params.get("id").toString());
        Integer status = Integer.parseInt(params.get("status").toString());
        String reason = (String) params.get("reason");
        
        boolean success = riderAuditService.auditRider(id, status, reason);
        
        if (success) {
            return ApiResponse.success("审核操作成功");
        } else {
            return ApiResponse.error("审核操作失败");
        }
    }

    /**
     * 获取骑手列表
     */
    @GetMapping("/list")
    public ApiResponse getRiderList(
            @RequestParam(required = false) String keyword,
            @RequestParam(required = false) Integer status,
            @RequestParam(required = false, defaultValue = "1") Integer page,
            @RequestParam(required = false, defaultValue = "10") Integer size) {
        
        Map<String, Object> result = riderAuditService.getRiderList(keyword, status, page, size);
        return ApiResponse.success(result);
    }
} 